<template>
	<view class="page">
		
		<navBar title="账户"></navBar>
		
		<!-- <view class="content" @click="setAlipay">
			<view class="tag flex_r_around">
				<text>优先推荐</text>
			</view>
			<view class="item flex_center">
				<image :src="$util.prefix('wechat/public/select_s.png')" mode="aspectFill" class="select-image"
					v-if="type == 1"></image>
				<image @click.stop="type = 1" :src="$util.prefix('wechat/public/select.png')" mode="aspectFill"
					class="select-image" v-else></image>
				<image :src="$util.prefix('wechat/public/alipay.png')" mode="aspectFill" class="icon"></image>
				<view class="label">支付宝</view>
				<view class="text">{{ alipay.account || '' }}</view>
				<u-icon name="arrow-right" size="28rpx" color="#666666"></u-icon>
			</view>
		</view> -->

		<view class="content" @click="setBankCard">
			<view class="item flex_center">
				<image src="/static/public/select.png" mode="aspectFill" class="select-image"
					v-if="type == 2"></image>
				<image @click.stop="type = 2" src="/static/public/select_s.png" mode="aspectFill"
					class="select-image" v-else></image>
				<image :src="$util.prefix('public/bankcard.png')" mode="aspectFill" class="icon"></image>
				<view class="label">银行卡</view>
				<view class="text">{{ bank.card_no || '' }}</view>
				<u-icon name="arrow-right" size="28rpx" color="#666666"></u-icon>
			</view>
		</view>

		<button @click="confirm">确定</button>

	</view>
</template>

<script>
	import navBar from '@/compentents/navBar/navBar.vue';
	export default {
		data() {
			return {
				bank: {},
				alipay: {},

				// 1 支付宝   2 银行卡
				type: 2,
			}
		},
		components: {
			navBar
		},
		methods: {
			getUserBasicdata() {
				this.$get('/hui_fu/getUserBasicdata', {}, false).then(res => {
					this.bank = res.data;
				});
			},

			getWithdrawalAccount() {
				this.$get('/user_withdrawal/getWithdrawalAccount').then(res => {
					this.alipay = res.data;
				});
			},

			setAlipay() {
				this.$util.toUrl('/pages/bankcard/alipay');
			},

			setBankCard() {
				this.$util.toUrl('/pages/bankcard/bankcard');
			},

			confirm() {
				let pages = getCurrentPages();
				let prePage = pages[pages.length - 2]; //上一个页面
				if(this.type == 1){
					if(!this.alipay.account){
						return this.$util.msg('请添加支付宝信息');
					}
					prePage.$vm.setAccount(this.type,this.alipay);
				}else {
					if(!this.bank.card_no){
						return this.$util.msg('请添加银行卡信息');
					}
					prePage.$vm.setAccount(this.type,this.bank);
				}
				uni.navigateBack()
			},

		},

		onShow() {
			this.getUserBasicdata();
			this.getWithdrawalAccount();
		}
	}
</script>

<style lang="less" scoped>
	.page {
		min-height: 100vh;
		width: 100vw;
		background: #F1F1F1;
		padding: 32rpx 32rpx 130rpx;
	}

	.content {
		margin-bottom: 16rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		overflow: hidden;

		.tag {
			width: 128rpx;
			height: 40rpx;
			border-radius: 24rpx 0 24rpx 0;
			background: #FFEAEE;

			text {
				font-size: 24rpx;
				color: #FD6235;
			}
		}

		.item {
			padding: 32rpx 24rpx;

			.select-image {
				width: 40rpx;
				height: 40rpx;
			}

			.icon {
				width: 40rpx;
				height: 40rpx;
				margin: 0 16rpx 0 24rpx;
			}

			.babel {
				font-size: 32rpx;
				color: #131313;
			}

			.text {
				font-size: 32rpx;
				color: #131313;
				flex: 1;
				text-align: right;
				margin-right: 16rpx;
			}

		}
	}

	button {
		width: 662rpx;
		height: 96rpx;
		background: #FD2A53;
		border-radius: 48rpx;
		font-size: 28rpx;
		color: #FFFFFF;
		line-height: 96rpx;
		position: fixed;
		bottom: 30rpx;
		left: 50%;
		transform: translateX(-50%);
	}
</style>